package com.smarthome.core.operationservicemanager.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.smarthome.base.service.ShLaundryFeeService;
import com.smarthome.core.operationservicemanager.LaundryFeeService;
import com.smarthome.domain.bean.ShLaundryFee;
import com.smarthome.domain.common.Page;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * 
* @ClassName: LaundryFeeServiceImpl
* @Description: 洗衣费service接口实现类
* @author cyj
* @date 2016年4月12日 下午11:21:35
*
 */
@Service("laundryFeeService")
public class LaundryFeeServiceImpl implements LaundryFeeService {
	
	@Resource
	private ShLaundryFeeService shLaundryFeeService;

	@Override
	public ShLaundryFee getById(Long id) {
		return shLaundryFeeService.selectEntryById(id);
	}

	@Override
	public DataGrid qeuryDataGrid(ShLaundryFee laundryFee, PageHelper page) {
		Page<ShLaundryFee> pages = new  Page<ShLaundryFee>();
		pages.setCurrentPage(page.getPage());
		pages.setPageSize(page.getRows());
		if(StringUtils.isNotBlank(page.getSort())) {
			laundryFee.setOrderField(page.getSort());
		}
		if(StringUtils.isNotBlank(page.getOrder())) {
			laundryFee.setOrderFieldType(page.getOrder());
		}
		pages = shLaundryFeeService.selectPage(laundryFee, pages);
		DataGrid dataGrid = new DataGrid();
		dataGrid.setRows(pages.getResult());
		dataGrid.setTotal((long)pages.getTotalCount());
		return dataGrid;
	}

	@Override
	public Integer saveOrUpdate(ShLaundryFee laundryFee) {
		return shLaundryFeeService.saveOrUpdate(laundryFee);
	}

	@Override
	public Integer delete(Long id) {
		return shLaundryFeeService.deleteByIds(id);
	}

	@Override
	public boolean checkLaundryType(ShLaundryFee laundryFee) {
		if(laundryFee == null || StringUtils.isBlank(laundryFee.getLaundryType()) || laundryFee.getCompanyLaundryId() == null) {
			return false;
		}
		ShLaundryFee fee = new ShLaundryFee();
		fee.setLaundryType(laundryFee.getLaundryType());
		fee.setCompanyLaundryId(laundryFee.getCompanyLaundryId());
		List<ShLaundryFee> list = shLaundryFeeService.selectEntryList(fee);
		if(list != null && !list.isEmpty()) {
			if(list.get(0).getId().equals(laundryFee.getId())) {
				return true;
			}else {
				return false;
			}
		}
		return true;
	}

	@Override
	public List<ShLaundryFee> getList(ShLaundryFee laundryFee) {
		return shLaundryFeeService.selectEntryList(laundryFee);
	}

	

}
